<template>
	<view class="mask mask-show" v-if="visible" @touchmove.stop.prevent="preventTouchMove">
		<!-- 加载动画 -->
		<view class="container loading">
			<view class="shape shape1"></view>
			<view class="shape shape2"></view>
			<view class="shape shape3"></view>
			<view class="shape shape4"></view>
		</view>
		<!-- 加载文字 -->
		<view class="title">{{ text }}</view>
	</view>
</template>

<script>
	export default {
		name: 've-loading',
		props: {
			text: {
				type: String,
				default: '努力加载中~'
			},
			value: Boolean
		},
		computed: {
			visible: {
				set(val) {
					this.$emit("input", val);
				},
				get() {
					return this.value;
				}
			}
		},
		methods: {
			// 防止遮罩层滚动事件穿透
			preventTouchMove() {
				return
			},
			close_pop() {
				if (this.click == 'false' || this.click == false) {
					this.show = false
				}
			}
		},
	}
</script>

<style lang="scss" scoped>
	.mask {
		position: fixed;
		z-index: 99999;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		height: 100vh;
		width: 100vw;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		flex-wrap: wrap;
	}

	.mask.mask-show {
		background: #fff;
	}

	.title {
		margin-top: 24rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #9EA5BB;
		line-height: 40rpx;
	}

	/* loading加载动画的css */
	.container {
		width: 30px;
		height: 30px;
		position: relative;
	}

	.container.loading {
		-webkit-transform: rotate(10deg);
		transform: rotate(10deg);
	}

	.container.loading .shape {
		border-radius: 5px;
	}

	.container.loading {
		-webkit-animation: rotation 1s infinite;
		animation: rotation 1s infinite;
	}

	.container .shape {
		position: absolute;
		width: 10px;
		height: 10px;
		border-radius: 1px;
	}

	.container .shape.shape1 {
		left: 0;
		background-color: #3072f6;
	}

	.container .shape.shape2 {
		right: 0;
		background-color: #3072f6;
	}

	.container .shape.shape3 {
		bottom: 0;
		background-color: #3072f6;
	}

	.container .shape.shape4 {
		bottom: 0;
		right: 0;
		background-color: #3072f6;
	}

	.loading .shape1 {
		-webkit-animation: animation2shape1 0.5s ease 0s infinite alternate;
		animation: animation2shape1 0.5s ease 0s infinite alternate;
	}

	@-webkit-keyframes animation2shape1 {
		from {
			-webkit-transform: translate(0, 0);
			transform: translate(0, 0);
		}

		to {
			-webkit-transform: translate(20px, 20px);
			transform: translate(20px, 20px);
		}
	}

	@keyframes animation2shape1 {
		from {
			-webkit-transform: translate(0, 0);
			transform: translate(0, 0);
		}

		to {
			-webkit-transform: translate(20px, 20px);
			transform: translate(20px, 20px);
		}
	}

	.loading .shape2 {
		-webkit-animation: animation2shape2 0.5s ease 0s infinite alternate;
		animation: animation2shape2 0.5s ease 0s infinite alternate;
	}

	@-webkit-keyframes animation2shape2 {
		from {
			-webkit-transform: translate(0, 0);
			transform: translate(0, 0);
		}

		to {
			-webkit-transform: translate(-20px, 20px);
			transform: translate(-20px, 20px);
		}
	}

	@keyframes animation2shape2 {
		from {
			-webkit-transform: translate(0, 0);
			transform: translate(0, 0);
		}

		to {
			-webkit-transform: translate(-20px, 20px);
			transform: translate(-20px, 20px);
		}
	}

	.loading .shape3 {
		-webkit-animation: animation2shape3 0.5s ease 0s infinite alternate;
		animation: animation2shape3 0.5s ease 0s infinite alternate;
	}

	@-webkit-keyframes animation2shape3 {
		from {
			-webkit-transform: translate(0, 0);
			transform: translate(0, 0);
		}

		to {
			-webkit-transform: translate(20px, -20px);
			transform: translate(20px, -20px);
		}
	}

	@keyframes animation2shape3 {
		from {
			-webkit-transform: translate(0, 0);
			transform: translate(0, 0);
		}

		to {
			-webkit-transform: translate(20px, -20px);
			transform: translate(20px, -20px);
		}
	}

	.loading .shape4 {
		-webkit-animation: animation2shape4 0.5s ease 0s infinite alternate;
		animation: animation2shape4 0.5s ease 0s infinite alternate;
	}

	@-webkit-keyframes animation2shape4 {
		from {
			-webkit-transform: translate(0, 0);
			transform: translate(0, 0);
		}

		to {
			-webkit-transform: translate(-20px, -20px);
			transform: translate(-20px, -20px);
		}
	}

	@keyframes animation2shape4 {
		from {
			-webkit-transform: translate(0, 0);
			transform: translate(0, 0);
		}

		to {
			-webkit-transform: translate(-20px, -20px);
			transform: translate(-20px, -20px);
		}
	}
</style>
